#ifndef _CAN_MOTOR_H_   
#define _CAN_MOTOR_H_  

#include "bsp_can.h"

#define CAN_Motor_ID_Base		0x201

#define M_PI (3.141592654f)

#define M3508_CntToAngle(cnt)				((float)(cnt/8192.f    * M_PI  / 19))		
#define M2006_CntToAngle(cnt)				((float)(((cnt/8192.f) * M_PI) / 36.f))
#define M2006_AngleToCnt(angle)			((float)((angle/M_PI) * 36.0f  * 8192))
	
typedef enum
{
	CAN_Motor_ID1  = 0x201,
	CAN_Motor_ID2  = 0x202,
	CAN_Motor_ID3  = 0x203,
	CAN_Motor_ID4  = 0x204,
								 
	CAN_Motor_ID5  = 0x205,
	CAN_Motor_ID6  = 0x206,
	CAN_Motor_ID7  = 0x207,
	CAN_Motor_ID8  = 0x208,
	
	CAN_Motor_ID9  = 0x209,
	CAN_Motor_ID10 = 0x20A,
	CAN_Motor_ID11 = 0x20B,
	CAN_Motor_ID12 = 0x20C,
	
	CAN_Motor_ID13 = 0x20D,
	CAN_Motor_ID14 = 0x20E,
	CAN_Motor_ID15 = 0x20F,
	CAN_Motor_ID16 = 0x210,
}CAN_Message_ID;

/* 支撑数据 */
typedef struct {
	uint16_t frist_cnt;				//上电计数	
	int16_t fris_angle;				//上电角度	
	int16_t last_angle;				//上一次电机角度	
	int32_t round_cnt;				//电机旋转圈数	
}CAN_MotorSupport_t;

typedef struct {
	int16_t angle;						//电机角度
	int32_t total_angle;			//电机总转角度
	int16_t speed;						//电机速度
	int16_t torque_current;		//反馈转矩电流
	int16_t control_current;	//电机控制电流
	uint8_t temperature;			//电机温度
}CAN_Fback_Inf;

/* 核心函数 */
void send_can1_motor_current(void);
void send_can2_motor_current(void);
void can_motor_updata(uint32_t StdId, uint8_t *rxbuff);

/* 通用接口 */
void CAN_Motor_setCurrent(CAN_Message_ID m3508_ID, int16_t current);
int16_t CAN_Motor_getSpeed(CAN_Message_ID m3508_ID);
int32_t CAN_Motor_getTotalAngle(CAN_Message_ID m3508_ID);
int16_t CAN_Motor_getAngle(CAN_Message_ID m3508_ID);

extern CAN_Fback_Inf can_motor_inf[];
#endif 
